home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / UTIL / Folder・Icon・Opener 1.0.1.sit / Folder•Icon•Opener 1.0.1 / source code / sources / FIOpen.AE.c next >
Text File  |  1996-05-05  |  7KB  |  250 lines

  1. /*
  2.  *--------------------------------------------------------------
  3.  * FIOpen.AE.c
  4.  *--------------------------------------------------------------
  5.  *    Copyright ゥ Fumio Rokkaku, 1996
  6.  *--------------------------------------------------------------
  7.  */
  8. #pragma once
  9.  
  10. /* System Headers */
  11. #include <Memory.h>
  12. #include <AppleEvents.h>
  13. #include <AERegistry.h>
  14. #include <Aliases.h>
  15. #include <OSUtils.h>
  16. #include <Errors.h>
  17.  
  18. /* Project Headers */
  19. #include "FIOpen.h"
  20.  
  21. /*
  22.  *--------------------------------------------------------------
  23.  *  AppleEvent error kind messages
  24.  *--------------------------------------------------------------
  25.  */
  26. enum AEErrKinds {
  27.     /* message kinds */
  28.     iAEOpenApplication    = 1,
  29.     iAEOpenDocuments,
  30.     iAEPrintDocuments,
  31.     iAEQuitApplication,
  32.     iAEOpenSelection,
  33.     iAESendMyOwnData,
  34.     iAEUnknownEvents,
  35.  
  36.     /* error codes */
  37.     iAENotInstalled,
  38.     iAEInvalidConnect,
  39.     iAENotHandled,
  40.     iAEParameterErr,
  41.     iAEMemoryFull,
  42.     iAENotCoercion,
  43.     iAEWrongDataType,
  44.     iAEDecsNotFound,
  45.     iAEInvalDesc,
  46.     iAENoReplyComes,
  47.     iAETimeoutOccur,
  48.     iAEUnknownError,
  49.  
  50.     errAENotInstalled = -1
  51. };
  52.  
  53. /*
  54.  *--------------------------------------------------------------
  55.  *  number of required AppleEvents
  56.  *--------------------------------------------------------------
  57.  */
  58. enum constAEHandlers {
  59.     kOpenApp    = 0,
  60.     kOpenDoc,
  61.     kPrntDoc,
  62.     kQuitApp,
  63.     kNumOfAE
  64. };
  65.  
  66. /*
  67.  *--------------------------------------------------------------
  68.  *  AppleEvent handlers
  69.  *--------------------------------------------------------------
  70.  */
  71. pascal OSErr DoAEOpenApp(const AppleEvent *, AppleEvent *, long);
  72. pascal OSErr DoAEOpenDoc(const AppleEvent *, AppleEvent *, long);
  73. pascal OSErr DoAEPrntDoc(const AppleEvent *, AppleEvent *, long);
  74. pascal OSErr DoAEQuitApp(const AppleEvent *, AppleEvent *, long);
  75.  
  76. /*
  77.  *--------------------------------------------------------------
  78.  *  static fucntions only used within this source
  79.  *--------------------------------------------------------------
  80.  */
  81. static OSErr GotRequiredParams(const AppleEvent *);
  82.  
  83. /*
  84.  *--------------------------------------------------------------
  85.  * static global: AppleEvent Hander Universal ProcPtr
  86.  *--------------------------------------------------------------
  87.  */
  88. static AEEventHandlerUPP gMyAEUPPs[kNumOfAE];
  89.  
  90. /*
  91.  *--------------------------------------------------------------
  92.  * SetUpMyAppleEvent
  93.  *--------------------------------------------------------------
  94.  *    set up Apple Event procedure
  95.  *    if AppleEvent is not supported, do nothing in here
  96.  *--------------------------------------------------------------
  97.  */
  98. Boolean SetUpMyAppleEvent(void)
  99. {
  100.     OSErr    result = noErr;
  101.  
  102.     gDragAndDrop = gDoubleClick = false;
  103.  
  104.     /* make AppleEvent handler UPPs */
  105.     gMyAEUPPs[kOpenApp] = NewAEEventHandlerProc(DoAEOpenApp);
  106.     gMyAEUPPs[kOpenDoc] = NewAEEventHandlerProc(DoAEOpenDoc);
  107.     gMyAEUPPs[kPrntDoc] = NewAEEventHandlerProc(DoAEPrntDoc);
  108.     gMyAEUPPs[kQuitApp] = NewAEEventHandlerProc(DoAEQuitApp);
  109.  
  110.     /* install required AppleEvents */
  111.     AEInstallEventHandler(kCoreEventClass, kAEOpenApplication,
  112.             gMyAEUPPs[kOpenApp], 0, false);
  113.     AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments,
  114.             gMyAEUPPs[kOpenDoc], 0, false);
  115.     AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments,
  116.             gMyAEUPPs[kPrntDoc], 0, false);
  117.     AEInstallEventHandler(kCoreEventClass, kAEQuitApplication,
  118.             gMyAEUPPs[kQuitApp], 0, false);
  119.  
  120.     return (result == noErr);
  121. }
  122. /*
  123.  *--------------------------------------------------------------
  124.  * RemoveMyAppleEvent
  125.  *--------------------------------------------------------------
  126.  *    delete AppleEvent handlers
  127.  *--------------------------------------------------------------
  128.  */
  129. void RemoveMyAppleEvent(void)
  130. {
  131.     int   i;
  132.  
  133.     for (i = 0; i < kNumOfAE; ++i) {
  134.         if (gMyAEUPPs[i] != nil) {
  135.             DisposeRoutineDescriptor(gMyAEUPPs[i]);
  136.         }
  137.     }
  138. }
  139. /*
  140.  *--------------------------------------------------------------
  141.  * DoAEOpenApp
  142.  *--------------------------------------------------------------
  143.  *    Open Application event: do nothing
  144.  *--------------------------------------------------------------
  145.  */
  146. pascal OSErr DoAEOpenApp(const AppleEvent *theAE, AppleEvent *reply, long refCon)
  147. {
  148. #pragma unused (theAE, reply, refCon)
  149.  
  150.     gDoubleClick = true;
  151.     OpenAboutDialog();
  152.     return (noErr);
  153. }
  154. /*
  155.  *--------------------------------------------------------------
  156.  * DoAEOpenDoc
  157.  *--------------------------------------------------------------
  158.  *    Open Document event: do open
  159.  *--------------------------------------------------------------
  160.  */
  161. pascal OSErr DoAEOpenDoc(const AppleEvent *theAE, AppleEvent *reply, long refCon)
  162. {
  163.     #pragma unused (reply, refCon)
  164.  
  165.     AEDescList    fileSpecList = {typeNull, nil};
  166.     long        listCount;
  167.     OSErr        result;
  168.  
  169.     result = AEGetParamDesc(theAE, keyDirectObject, typeAEList, &fileSpecList);
  170.     if (result == noErr) {
  171.         result = GotRequiredParams(theAE);
  172.     }
  173.     if (result == noErr) {
  174.         result = AECountItems(&fileSpecList, &listCount);
  175.     }
  176.     if (result == noErr) {
  177.  
  178.         long    index;
  179.         for (index = 1; index <= listCount; index++) {
  180.  
  181.             AEKeyword    keyword;
  182.             DescType    itsType;
  183.             Size        actualSize;
  184.             FSSpec        gotSpec;
  185.  
  186.             result = AEGetNthPtr(&fileSpecList, index, typeFSS, &keyword, &itsType,
  187.                             (Ptr)&gotSpec, sizeof(FSSpec), &actualSize);
  188.             if (result == noErr) {
  189.                 result = OpenFolderIcon(&gotSpec);
  190.             } else {
  191.                 break;
  192.             }
  193.         }
  194.     }
  195.     AEDisposeDesc(&fileSpecList);
  196.     gDragAndDrop = true;
  197.     return (result);
  198. }
  199. /*
  200.  *--------------------------------------------------------------
  201.  * DoAEPrntDoc
  202.  *--------------------------------------------------------------
  203.  *    Apple Event Print procedure
  204.  *--------------------------------------------------------------
  205.  */
  206. pascal OSErr DoAEPrntDoc(const AppleEvent *theAE, AppleEvent *reply, long refCon)
  207. {
  208.     #pragma unused (theAE, reply, refCon)
  209.  
  210.     gDone = true;
  211.     return (errAEEventNotHandled);
  212. }
  213. /*
  214.  *--------------------------------------------------------------
  215.  * DoAEQuitApp
  216.  *--------------------------------------------------------------
  217.  *    Apple Event Quit procedure
  218.  *--------------------------------------------------------------
  219.  */
  220. pascal OSErr DoAEQuitApp(const AppleEvent *theAE, AppleEvent *reply, long refCon)
  221. {
  222.     #pragma unused (theAE, reply, refCon)
  223.  
  224.     gDone = true;
  225.     return (noErr);
  226. }
  227. /*
  228.  *--------------------------------------------------------------
  229.  * GotRequiredParams
  230.  *--------------------------------------------------------------
  231.  *    Apple Event requred parameter parser
  232.  *--------------------------------------------------------------
  233.  */
  234. static OSErr GotRequiredParams(const AppleEvent *theAE)
  235. {
  236.     DescType    returnedType;
  237.     Size        actualSize;
  238.     OSErr        result;
  239.  
  240.     result = AEGetAttributePtr(theAE, keyMissedKeywordAttr, typeWildCard,
  241.                              &returnedType, nil, 0, &actualSize );
  242.  
  243.     if (result == errAEDescNotFound) {
  244.         return (noErr);
  245.     } else if (result == noErr) {
  246.         return (errAEEventNotHandled);
  247.     }
  248.     return (result);
  249. }
  250.